package com.gundam.tools.lint.checks

import com.android.tools.lint.detector.api.*
import com.intellij.psi.PsiMethod
import org.jetbrains.uast.UCallExpression

/**
 *
 * @author wpq
 * @version 1.0
 */
@Suppress("UnstableApiUsage")
class ToastDetector : Detector(), Detector.UastScanner {

    override fun getApplicableMethodNames(): List<String>? {
        return listOf("makeText")
    }

    override fun visitMethodCall(context: JavaContext, node: UCallExpression, method: PsiMethod) {
        if (context.evaluator.isMemberInClass(method, "android.widget.Toast")) {
            context.report(ISSUE, node, context.getLocation(node), "请使用DKToast，保证样式统一")
        }
    }

    companion object {
        @JvmField
        val ISSUE = Issue.create(
                // ID: used in @SuppressLint warnings etc
                "DKToast",

                // Title -- shown in the IDE's preference dialog, as category headers in the
                // Analysis results window, etc
                "统一使用DKToast",

                // Full explanation of the issue; you can use some markdown markup such as
                // `monospace`, *italic*, and **bold**.
                "统一使用DKToast，保证样式统一",
                Category.USABILITY,
                7,
                Severity.WARNING,
                Implementation(ToastDetector::class.java, Scope.JAVA_FILE_SCOPE))
    }
}